package com.damon.JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.damon.entity.MonitorConfigByBitEntity;
import com.damon.utils.DbUtil;

public class MonitorConfigJDBC {
	private static Logger logger = LoggerFactory.getLogger(MonitorConfigJDBC.class);
	
	public static ArrayList<MonitorConfigByBitEntity> getMonitorConfigByBitList() {

		String sql = "select * from wcs_monitor_config_bit where is_used='1'";
		Connection connection = DbUtil.getConnection();
		Statement statement = null;
		ResultSet resultSet;
		//monitor_no,db_no,offset_byte,offset_bit,byte_length,device_type,device_desc
		ArrayList<MonitorConfigByBitEntity> deviceList = new ArrayList<>();
		try {
			statement = connection.createStatement();
			resultSet = statement.executeQuery(sql);
			while(resultSet.next()) {
				MonitorConfigByBitEntity entity = new MonitorConfigByBitEntity();
				entity.setId(resultSet.getInt("id"));
				entity.setMonitor_No(resultSet.getString("monitor_no"));
				entity.setDbNo(resultSet.getInt("db_no"));
				entity.setOffsetBit(resultSet.getInt("offset_bit"));
				entity.setOffsetByte(resultSet.getInt("offset_byte"));
				entity.setByteLength(resultSet.getInt("byte_length"));
				entity.setDeviceType(resultSet.getString("device_type"));
				entity.setDeviceDesc(resultSet.getString("device_desc"));
				deviceList.add(entity);
			}
		} catch (SQLException e) {
			logger.error("查询设备表出错！！");
			e.printStackTrace();
		}finally {
			try {
				statement.close();
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return deviceList;
	}
	
}
